<?php
require_once('../phplib/include.inc.php');

class ProductAdmin extends PageBase{
	public function Ini(){
		PageBase::RequireLogin();
		$this->GetTypes();
		$this->GetProducts();
	}
	public function GetTypes(){
		$db = getDb();
		$db->connect();
		$types = $db->fetch("SELECT * FROM type_t");
		$types[count($types)] = array("tid" => 0,"tname" => "所有数据");
		$this->assign('types',$types);
	}
	public function GetProducts(){
		$tid = @intval($_REQUEST['tid']);
		$sql = "SELECT pt.*,tt.tname FROM product_t AS pt LEFT JOIN type_t AS tt ON pt.tid=tt.tid";
		if($tid > 0)
			$sql .= " WHERE pt.tid=$tid";
		$db = getDb();
		$db->connect();
		$re = $db->fetch($sql);
		$products = array();
		$counter = 0;
		for($i=0;$i<count($re);$i++){
			$pid = intval($re[$i]['pid']);
			if(Util::HaveRight_Or(array($pid*10,$pid*10 + 1,$pid*10 + 2,1))){
				$products[$counter] = $re[$i];
				$products[$counter]['canadd'] = Util::HaveRight_Or(array(1,2));
				$products[$counter]['canmodify'] = Util::HaveRight_Or(array(1,$pid*10+1));
				$products[$counter]['candelete'] = Util::HaveRight_Or(array(1,$pid*10+2));
				$counter += 1;
			}
		}
		$this->assign('products',$products);
	}
}
$productadmin = new ProductAdmin("file:".dirname(__FILE__)."/../home/productadmin.tpl.html");
$productadmin->display();
?>